<?php

namespace app\index\controller;

use app\common\controller\Frontend;

class User extends Frontend
{

    protected $model = null;
    protected $layout = '';

    public function _initialize()
    {
        parent::_initialize();
        $this->model = model('User');
    }

    public function uploadCard()
    {
        if ($this->request->isAjax() && $this->request->isPost()) {
            $post = $this->request->post();
            $this->model->startTrans();
            if (($id = $this->model->insertGetId([
                'status' => 1,
                'number' => $post['number'],
                'mobile' => $post['mobile'],
                'createtime' => time(),
                'updatetime' => time(),
                ]))) {
                if (!$this->model->name('user_real_name')
                        ->insert([
                            'user_id' => $id,
                            'auth_table' => $post['auth_table'],
                            'handheld_card' => $post['handheld_card'],
                            'status' => 1,
                            'createtime' => time(),
                            'updatetime' => time(),
                        ])) {
                    $this->model->rollback();
                }
            }
            $this->model->commit();
            return $this->success();
        }
        return $this->error();
    }

}
